/**
 * 
 */
package com.revenco.bi.dao.nutz;

import java.util.List;

import org.nutz.dao.Cnd;
import org.nutz.dao.Condition;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.springframework.stereotype.Repository;

import com.revenco.bi.dao.TnChartDataitemsDao;
import com.revenco.bi.model.TnChartDataitems;

/**
 * @author ghq
 * @version $Revision:1.0.0, 2014年1月24日10:31:45
 */
@Repository
public class TnChartDataitemsDaoImpl extends AstractDaoImpl implements
		TnChartDataitemsDao {

	// public List<TnChartDataitems> getChartDataitemsList(String chartId) {
	// Condition condition=Cnd.where("chartId", "=", chartId);
	// return this.getDao().query(TnChartDataitems.class, condition);
	// }

	public TnChartDataitems getChartDataitemsById(String Id) {
		Condition condition = Cnd.where("dataitemsId", "=", Id);
		return (TnChartDataitems) this.getDao().query(TnChartDataitems.class,
				condition);
	}

	/**
	 * 保存图表数据配置表
	 */
	public void saveChartDataitemsInfo(TnChartDataitems tDataitems) {
		this.getDao().insert(tDataitems);

	}

	/**
	 * 更新图表数据配置表
	 */
	public void updateChartDataitemsInfo(TnChartDataitems tDataitems) {
		/*
		 * Chain c = Chain.from(tDataitems); Condition con =Cnd.where("chartId",
		 * "=", tDataitems.getChartId()); con =Cnd.where("yFieldName", "=",
		 * tDataitems.getyFieldName());
		 * this.getDao().update(TnChartBaseinfo.class, c, con);
		 */
		this.getDao().update(tDataitems);

	}

	/**
	 * 用名字和图表id查找记录
	 */
	public TnChartDataitems getChartDataitemsByIdName(String chartId,
			String name) {
		TnChartDataitems tnChartDataitems;
		Condition con = Cnd.where("CHART_ID", "=", chartId);
		con = Cnd.where("SERIES_ID", "=", name);
		tnChartDataitems = this.getDao().fetch(TnChartDataitems.class, con);
		return tnChartDataitems;

	}

	public List<TnChartDataitems> getChartDataitemsList(String chartId) {
		List<TnChartDataitems> tnChartDataitemsList;
		Condition condition = Cnd.where("CHART_ID", "=", chartId);
		tnChartDataitemsList = this.getDao().query(TnChartDataitems.class,
				condition);
		return tnChartDataitemsList;
	}

	/**
	 * 根据图表id删除一个集合
	 * 
	 * @param chartId
	 * @return
	 */
	public boolean deleteChartDataitemsByIdName(String chartId) {
		boolean delFlag = false;
		List<TnChartDataitems> dleTnChartDataitemsList = getChartDataitemsList(chartId);
		for (TnChartDataitems t : dleTnChartDataitemsList) {
			this.getDao().delete(t);
		}
		delFlag = true;
		return delFlag;

	}

	public void deleteChartDataitems(TnChartDataitems td) {
		this.getDao().delete(td);
	}
	
	public void deleteByChartId(String chartId) {
		Sql sql = Sqls
				.create("Delete FROM FRNT.TN_CHART_DATAITEMS WHERE CHART_ID = @chartId");
		sql.params().set("chartId", chartId);
		this.getDao().execute(sql);
	}
}
